<?php
/**
 * file serifeaturecontroller.php
 * Created on 2015-4-17 下午5:31:39 
 * Create by xiweijie
 */
namespace haibao\cms\business\control\pc\channel\exclusive;

use haibao\cms\business\control\PublicController;
use haibao\cms\business\control\FeatureController;

class SeriFeatureController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	const FEATURE_TYPE_SERIAL = 1;
	const FEATURE_TYPE_COLUMN = 2;
	
    public function __construct($updateTime = null,$controlId,$isPublish){
        $this->savaLog();
        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    /**
     * 显示模版内容（模版动态数据的绑定和模版输出）
     * @param : String $content
     * @param : Array $controlData;
     */
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        $temp = array();
        if($controlData['auto']){
            foreach($controlData['auto'] as $data){
                $parameterValue = json_decode($data['ParameterValue'],true);
                $parameterValue['id'] = $data['Id'];
                $temp[] = $parameterValue;
            }
        }
        $articleList = array();
        $this->assign('exclusiveDomain', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_EXCLUSIVE));
        $this->assign('columnList', $temp);
        $defaultList = '';
        $firstFeature = '';
        if(!empty($temp)){
            $default = $temp[0];
            $this->assign('default', $default);
            if(isset($default['cId'])){
                $defaultList = $this->getActualData($default);
                $firstFeature = array_shift($defaultList);
                $firstFeature->ListDate =  $firstFeature->PublishTime->format('Y-m-d');
                $this->assign('firstFeature', $firstFeature);
                $this->assign('defaultList', $defaultList);
                $serialUrl = null;
                $type = self::FEATURE_TYPE_COLUMN;
                if(isset($default['url'])){
                	$serialUrl = $default['url'];
                }
                if(isset($default['type'])){
                	$type = $default['type'];
                }
                $this->assign('serialUrl', $serialUrl);
                $this->assign('type', $type);
            }
        }
        
        $isNewHtml = $this->generateHtml($path,$content);
        
        $content = $this->getHtml($path);
        // 解析内容 更换链接
        $content = $this->replaceCDNLink($content);
        return $content;
    }
    
    private function getActualData($dataCondition){
        $cid = $dataCondition['cId'];
        $type = self::FEATURE_TYPE_COLUMN;
        if(isset($dataCondition['type'])){
        	$type = $dataCondition['type'];
        }
        if($type == self::FEATURE_TYPE_SERIAL){
        	$result = FeatureController::getserialInfoById($cid,3);
        }else{
        	$result = FeatureController::getFeatureByColumnId($cid);
        }
        foreach ($result as $key=>$list){
            $list->Title = $list->FeatureDefine->FeatureName;
            $list->Pic = $list->Image->Filename;
            $list->Description = $this->cutTitle($list->FeatureDefine->Description, 200);
        }
        return $result;
    }
}

